package com.fanix5.javamvvm.viewmodel.state;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.fanix5.javamvvm.api.RetrofitUtil;
import com.fanix5.javamvvm.base.BaseViewModel;
import com.fanix5.javamvvm.bean.BannerBean;
import com.fanix5.javamvvm.event.EventLiveData;
import com.fanix5.javamvvm.network.BaseObserver;
import com.fanix5.javamvvm.network.RxSchedulers;
import com.orhanobut.logger.Logger;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.List;

import io.reactivex.disposables.Disposable;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class HomeFragmentViewModel extends BaseViewModel {


    public EventLiveData<List<BannerBean>> bannerLiveData = new EventLiveData<>();

    public void getBannerList(){
        getHttp().getBannerList().compose(RxSchedulers.applySchedulers())
                .subscribe(new BaseObserver<ResponseBody>() {
                    @Override
                    public void onSuccess(ResponseBody result) {
                        Log.e("TAG", "onSuccess1: "+result );

                        try {
                            JSONObject jsonObject = new JSONObject(result.string());
                            Log.e("TAG", "onSuccess2: "+ jsonObject );
                        }catch (JSONException | IOException e){
                            e.printStackTrace();
                        }

                    }

                    @Override
                    public void onFailure(String errMsg, boolean isNetError) {

                    }

                    @Override
                    public void onSubscribe(Disposable d) {
                        addSubscribe(d);
                    }
                });
    }

}
